
let handleNavigationBar = require("../../utils/formatCurrency").handleNavigationBar;
let download = require("../../utils/formatCurrency").download;
const app = getApp();
Page({
  data: {
    subsidiarys: [],
    date:''
  },

  onLoad: function (options) {
    wx.showLoading({
      title: '加载中',
    })

    handleNavigationBar(app.globalData.company)
    this.data.date = options.data;
    let that = this;
    wx.request({
      url: app.globalData.url + 'api/subjects/findall',
      method: 'POST',
      header: {
        token: app.globalData.token,
        version: app.globalData.version
      },
      data: {
        accountBookId: app.globalData.accountBookId
      },
      success: function (res) {
        wx.request({
          url: app.globalData.url + 'api/details/find',
          method: 'POST',
          header: {
            token: app.globalData.token,
            version: app.globalData.version
          },
          data: {
            accountBookId: app.globalData.accountBookId,
            endPeriod: options.data,
            startPeriod: options.data,
            subjectId: res.data.subjects[0].id,
            assistingAccountId: null
          },
          success: function (res) {
            that.handleData(res.data.subsidiarys)
          }
        })
      }
    })
  },

  handleData(data){
    wx.hideLoading()
    
    this.setData({
      subsidiarys: data
    })
  },

  downLoad() {
    let url = app.globalData.url + 'api/export/pdf/subsidiaryledger/all?accountBookId=' + app.globalData.accountBookId + '&startPeriod=' + this.data.date + '&endPeriod=' + this.data.date + '&version=' + app.globalData.version + '&token=' + app.globalData.token
    download(url)
  }
})